package com.xxxx.server.controller;


import com.xxxx.server.pojo.RespBean;
import com.xxxx.server.pojo.Salary;
import com.xxxx.server.service.impl.SalaryServiceImpl;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhoubin
 */
@RestController
@RequestMapping("/salary/sob")
public class SalaryController {
    /**
     * Controller调用service层
     * Service调用dao层（Mapper层）
     查找单个用Mapper层的增删改查
     查找多个用Service层的增删改查
     */

    @Resource
    private SalaryServiceImpl salaryService;

    // 查询所有的账套信息

 /* @GetMapping("/")
    public List<Salary> select(Salary salary){
      return salaryService.select();
  }*/

    @GetMapping("/")
    public List<Salary> selectAll(Salary salary){
        List<Salary> list = salaryService.list();
        return list;
    }
    /**
     * 添加账套信息
     *
     */

    /**
     * 添加员工账套
     */
    @PostMapping("/")
    public RespBean addSalary(@RequestBody Salary salary){
        salary.setCreateTime(LocalDateTime.now());
        if(salaryService.save(salary)){
            return RespBean.success("添加成功");
        }else{
            return RespBean.error("添加失败");
        }

    }
    /**
     * 删除账套信息（根据Id删除账套信息）
     */
    @DeleteMapping("/{id}")
    public RespBean deleteSalary(@PathVariable Integer id ){
        if(salaryService.removeById(id)){
            return RespBean.success("删除成功");
        }else{
            return RespBean.error("删除失败");
        }

    }
    /**
     * 修改员工账套
     */
    @PutMapping("/")
    public RespBean updateSalary( @RequestBody  Salary salary){
        boolean b = salaryService.updateById(salary);
        if(b){
            return RespBean.success("修改成功");
        }else {
            return RespBean.error("修改失败");
        }
    }
    /**
     * 刷新
     */



}
